package homework;
import java.util.Arrays;
import java.util.Random;
public class day05 {
    public static void main(String[] args) {
        for (int num=1;num<=9;num++){
            for (int i=1;i<=num;i++){
                System.out.print(i+"*"+num+"="+i*num+"\t");
            }
            System.out.println();
        }
        System.out.println();
        //数组小代码练习之声明,初始化
        int[] arr = new int[3];//0,0,0
        int[] arr1 = {2,4,6,8};
        int[] arr2 = new int[]{2,4,6,8};
        int[] arr3;
        arr3 = new int[]{2,3,4};
        //访问
        int[] brr = new int[3];
        System.out.println(arr.length);
        System.out.println();
        brr[0] = 100;
        brr[1] = 200;
        brr[2] = 300;
        System.out.println(brr[brr.length-1]);
        System.out.println();
        //遍历
        int[] crr = new int[10];
        for (int i=0;i<crr.length;i++){
            crr[i] = (int)(Math.random()*100);
            System.out.println(crr[i]);
        }
        System.out.println();
        //复制
        int[] a ={10,20,30,40};
        a = Arrays.copyOf(a,a.length+1);
        for (int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
        System.out.println();
        //求数组元素最大值,并放在最后一个元素的下一个位置
        int[] b = new int[10];
        for (int i=0;i<b.length;i++){
            b[i] = (int)(Math.random()*100);
            System.out.println(b[i]);
        }
        int max = b[0];
        for (int i=1;i<b.length;i++){
            if (b[i]>max){
                max = b[i];
            }
        }
        System.out.println("最大值为:"+max);
        b =Arrays.copyOf(b,b.length+1);
        b[b.length-1] = max;
        for (int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }
        System.out.println();
        //数组的升序排列
        System.out.println("排序前:");
        Random rand = new Random();
        int[] c = new int[10];
        for (int i=0;i<c.length;i++){
            c[i] = rand.nextInt(100);
            System.out.println(c[i]);
        }

        Arrays.sort(c);
        System.out.println("排序后:");
        for (int i=0;i<c.length;i++){
            System.out.println(c[i]);
        }
        System.out.println("倒着排");
        for (int i=c.length-1;i>=0;i--){
            System.out.println(c[i]);
        }
        System.out.println("第1个元素为:"+c[0]);













    }
}
